<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends MY_Controller {

	/**
	 * Index Page for this controller.get_ask_active_user
	 *
	 */
	public function index()
	{
		//获取视频课list
		$this->load->model('courses');
		$video_list = $this->courses->get_recomend_course_list(6);
		// print_r($video_list);exit;
		$this->smarty->assign("video_list", $video_list);
		

		//获取一条直播
		$this->load->model('lives');
		$zhibo = $this->lives->get_last_zhibo();
		if($zhibo){
			$time = time();
			if($zhibo['start_time'] < $time && $time < $zhibo['end_time']){
				$zhibo['live_status'] = 2;
			}
			if($zhibo['start_time'] > $time){
				$zhibo['live_status'] = 1;
			}
			if($zhibo['end_time'] < $time){
				$zhibo['live_status'] = 3;
			}
			$this->smarty->assign("zhibo", $zhibo);
		}

		

		//获取班课list
		$this->load->model("Courseo2o_model");
		$banke_list = $this->Courseo2o_model->get_banke_list($this->school_id,6);
		$this->smarty->assign("banke_list", $banke_list);

		//面授课分类
		$this->load->model('Courseo2o_model');
    	$offline_cate_list = $this->Courseo2o_model->get_offline_cate($this->school_id);
		$this->smarty->assign("offline_cate_list", $offline_cate_list);


		//获取学校推荐老师
		$this->load->model('School_model');
		$index_campus = $this->School_model->get_school_campus($this->school_id, 0, 3);
		$this->smarty->assign("index_campus", $index_campus['result']);


		//取题库内容
		$this->load->model("Tk_categorys");
		$this->load->model("Subjects");
		$conditions['school_id'] = $this->school_id;
		$conditions['uid'] = $this->user_data['id'];
		$tk_category_list = array();
		$tk_category_data = $this->Tk_categorys->get_tk_category_list(0, 6, $conditions);
		if($tk_category_data['count'] > 0){
			$tk_category_list = $tk_category_data['result'];
			foreach ($tk_category_list as $key => $value) {
				$conditions['tk_category_id'] = $value['id'];
				// $subject_data = $this->Subjects->get_subject_list(0, 2, $conditions);
				$subject_data = $this->Subjects->get_school_subject_list(0, 2, $conditions);
				// print_r($subject_data);
				if($subject_data['count'] > 0){
					$tk_category_list[$key]['subject'] = $subject_data['result'];	
				}else{
					unset($tk_category_list[$key]);
				}
			}
		}

        $this->load->model("School_page_modulars");
        $have_modular = $this->School_page_modulars->get_school_page_modulars($this->school_id);
        $have_modular_id = array_column($have_modular, "id");
        $shixun_list = array();
        $shixun_data = array();
		if(in_array(9, $have_modular_id)){
			$data = json_decode(file_get_contents("http://123.206.137.187:804/HandlerData.ashx?action=GetZhangtaoInfo"),true);
			if(!empty($data['rows']) && count($data['rows']) > 0){
				$this->load->model("Shixuns");
				$ids = '';
				foreach ($data['rows'] as $key => $value) {
					$shixun_list[$value['Id']] = $value;
					if($key == 0){
						$ids .= "'" . $value['Id'] . "'";
					}else{
						$ids .= ",'" . $value['Id'] . "'";
					}
				}
				$pack_list = $this->Shixuns->get_sx_packages($ids);
				if($pack_list){
					foreach ($pack_list as $k => $v) {
						if(isset($shixun_list[$v['sx_id']]) && $v['status'] == 1){
							$shixun_list[$v['sx_id']]['status'] = $v['status'];
							$shixun_list[$v['sx_id']]['pack_id'] = $v['id'];
							$shixun_data[] = $shixun_list[$v['sx_id']];
						}
					}
				}
			}
			$shixun_data = array_slice($shixun_data, 0, 8);
		}

        $this->load->model("Newses");
        
        $new_list = $this->Newses->get_news10(6);

        $this->load->model("User_model");
        $ask_user = $this->User_model->get_ask_user();

        $this->load->model('Advertisings');
        $ad_conditions['ad_position_sign'] = "index-banner";
        $ad_conditions['school_id'] = $this->school_id;
        $banner_list = $this->Advertisings->get_list($ad_conditions);

        $this->load->model("Question_categorys");
        $question_category_list = $this->Question_categorys->get_top_categorys();

        $this->load->model("Questions");
        $question_list = $this->Questions->get_index_question($this->school_id);

        $this->smarty->assign("have_modular_id", $have_modular_id);
        $this->smarty->assign("question_category_list", $question_category_list);
		$this->smarty->assign("tk_category_list", $tk_category_list);
		$this->smarty->assign("shixun_list", $shixun_data);
		
		$this->smarty->assign("new_list", $new_list);
        $this->smarty->assign("question_list", $question_list);

        $this->smarty->assign("banner_list", $banner_list);
        $this->smarty->assign("ask_user", $ask_user);
		$this->smarty->display("index.html");
	}

	function test(){
		$data['pay_type'] = 9;
		$data['order_id'] = '9';
		$data['order_detail'] = 'ceshi,jihuarenwu';
		$data['status'] = 9;
		$this->db->insert("o2o_school_pay_logs", $data);
	}
}
